//战役结束Layer

var onCampaignSceneDestroyed = [];

var battleSum = {
	_mainNode : null,
	
	_jumpingText : null,
	
	Initialize : function(){
		this._mainNode = null;
	},
	
	ShowUI : function(isWin){
		var winSize = cc.director.getWinSize();
		
		this._mainNode = new cc.Node();
		this._mainNode.attr({x:0, y:0});
		campaignScene.canvaslayer.addChild(this._mainNode);
		
		var background = null;
		if (isWin){
			background = cc.LabelTTF.create("战 役 胜 利", "simhei", 72);
			background.setColor(cc.color(255, 50, 50));
		}else{
			background = cc.LabelTTF.create("战 役 失 败", "simhei", 72);
			background.setColor(cc.color(168, 168, 168));
		}
		this._mainNode.addChild(background);
		
		var hLine = new cc.Sprite(resource.white1010_png);
		hLine.attr({
			scaleX : 0.8 * winSize.width * 0.1,
			scaleY : 4 * 0.1,
			opacity : 191
		});
		this._mainNode.addChild(hLine);
		
		var battleScore = CalcBattleScore();
		
		var scoreLabel = cc.LabelTTF.create("用时: 0天   歼灭/伤亡 : 0/0\n\n控制区域增加 : 0(km2)\n\n战役得分 : 0", "simhei", 32);
		scoreLabel.setColor(cc.color(220, 220, 220));
		this._mainNode.addChild(scoreLabel);
		
		this._jumpingText = new JumpingText(scoreLabel,
			"用时: #NUM0天   歼灭/伤亡: #NUM1/#NUM2\n\n控制区域增加: #NUM3(km2)\n\n战役得分: #NUM4",
			[0,0,0,0,0],
			[battleScore.duration/40, battleScore.casualty[1]/40, battleScore.casualty[0]/40, battleScore.gainArea[0]/40, battleScore.score[0]/40],
			40/*tickCount*/,0.05/*tickTime*/
		);
		this._jumpingText.Start();
		
		var OKButton = this._CreateNormalButton("确定", this.OnOK);
		
		var OKMenu = cc.Menu.create(OKButton);
		OKMenu.attr({x:0, y:0});
		this._mainNode.addChild(OKMenu);
		
		ArrangeVertical(0.5 * winSize.width, 0.5 * winSize.height, 0.06 * winSize.height,
				[ background, hLine, scoreLabel, OKButton ]);
	},
	
	_CreateNormalButton : function(text,callback){
		var button = new cc.MenuItemImage(resource.ctrlbtnNormal_png,resource.ctrlbtnDown_png, resource.ctrlbtnDisable_png, callback, this);
		var label = cc.LabelTTF.create(text, "simhei", 28);
		label.setPosition(button.width * 0.5, button.height * 0.5);
		label.setColor(cc.color(0,0,0));
		button.addChild(label);
		return button;
	},
	
	HideUI : function(){
		if (this._mainNode != null){
			this._mainNode.removeFromParent();
			this._mainNode = null;
		}
	},
	
	OnOK : function(){
		battleSum._jumpingText.Stop();
		battleSum.HideUI();
		for (var idx in onCampaignSceneDestroyed)
			onCampaignSceneDestroyed[idx]();

		cc.director.runScene(sysMenuScene.Create());
	},
};